package org.dromara.system.controller.talent;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.bo.ServiceItemDeptBo;
import org.dromara.system.domain.vo.ServiceItemDeptVo;
import org.dromara.system.service.IServiceItemDeptService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 服务项目关联部门
 *
 * @author 毛宁川
 * @date 2025-07-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/talent/ServiceItemDept")
public class ServiceItemDeptController extends BaseController {

    private final IServiceItemDeptService serviceItemDeptService;

    /**
     * 查询服务项目关联部门列表
     */
    @SaCheckPermission("talent:ServiceItemDept:list")
    @GetMapping("/list")
    public TableDataInfo<ServiceItemDeptVo> list(ServiceItemDeptBo bo, PageQuery pageQuery) {
        return serviceItemDeptService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务项目关联部门列表
     */
    @SaCheckPermission("talent:ServiceItemDept:export")
    @Log(title = "服务项目关联部门", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ServiceItemDeptBo bo, HttpServletResponse response) {
        List<ServiceItemDeptVo> list = serviceItemDeptService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务项目关联部门", ServiceItemDeptVo.class, response);
    }

    /**
     * 获取服务项目关联部门详细信息
     *
     * @param serviceItemDeptId 主键
     */
    @SaCheckPermission("talent:ServiceItemDept:query")
    @GetMapping("/{serviceItemDeptId}")
    public R<ServiceItemDeptVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long serviceItemDeptId) {
        return R.ok(serviceItemDeptService.queryById(serviceItemDeptId));
    }

    /**
     * 新增服务项目关联部门
     */
    @SaCheckPermission("talent:ServiceItemDept:add")
    @Log(title = "服务项目关联部门", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ServiceItemDeptBo bo) {
        return toAjax(serviceItemDeptService.insertByBo(bo));
    }

    /**
     * 修改服务项目关联部门
     */
    @SaCheckPermission("talent:ServiceItemDept:edit")
    @Log(title = "服务项目关联部门", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ServiceItemDeptBo bo) {
        return toAjax(serviceItemDeptService.updateByBo(bo));
    }

    /**
     * 删除服务项目关联部门
     *
     * @param serviceItemDeptIds 主键串
     */
    @SaCheckPermission("talent:ServiceItemDept:remove")
    @Log(title = "服务项目关联部门", businessType = BusinessType.DELETE)
    @DeleteMapping("/{serviceItemDeptIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] serviceItemDeptIds) {
        return toAjax(serviceItemDeptService.deleteWithValidByIds(List.of(serviceItemDeptIds), true));
    }
}
